package com.atguigu.tingshu.dispatch.job;


import com.atguigu.tingshu.search.client.SearchFeignClient;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DispatchHandler {


    @Autowired
    private SearchFeignClient searchFeignClient;

    @Autowired
    private UserFeignClient userFeignClient;


    @XxlJob("updateTaskDB")
    public void updateTaskDB() {
        log.info("更新任务数据库");
    }


    @XxlJob("updateMongoDB")
    public void updateMongoDB() {
        searchFeignClient.updateLatelyAlbumRanking();
        log.info("更新MongoDB");
    }

    @XxlJob("updateUserVIPState")
    public void updateUserVIPState() {
        String jobParam = XxlJobHelper.getJobParam();
        log.info("更新用户VIP状态：{}", jobParam);
        userFeignClient.updateVipExpireStatus();
        log.info("更新用户VIP状态");
    }

    @XxlJob("updateParam")
    public void updateParam() {
        String jobParam = XxlJobHelper.getJobParam();
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("分片参数：{}，{}", shardIndex, shardTotal);
        log.info("更新参数：{}", jobParam);
    }
}